<?php
include 'EditDistanceCalculator.php';
set_time_limit(0);
$edCalc = new EditDistanceCalculator();

/*$fileName = 'eng_wikipedia_2010_10K-words.txt';
$file = fopen($fileName, 'r');

$words = fopen('clean.txt', 'w+');

$countingIndex = 1;
while (!feof($file)) {
	$line = fgets($file);
	list($index, $word, $count) = preg_split('/\s+/', $line);
	
	
	if ($countingIndex > 1000) {
		break;
	}
	if ($count > 1) {
		fwrite($words, $countingIndex . "\t" . $word . "\t"  . $count . PHP_EOL);
		$countingIndex++;
	}
	
}
fclose($words);
fclose($file);

die();*/
$file = fopen('clean.txt', 'r');
$words = array();
$counting = 1;
while (!feof($file)) {
	$line = fgets($file);
	list($index, $word, $count) = preg_split('/\s+/', $line);
	$words[] = $word;
	$counting++;
}
fclose($file);

$size = count($words);
echo 'Total words: ' . $size . '<br>';
$steps = 1;

$start = microtime(true);
for ($i = 0; $i < $size; $i++) {
	for ($j = 0; $j < $size; $j++) {
		if ($i != $j) {
			$result = $edCalc->calculate($words[$i], $words[$j]);
			$steps++;
		}
	}
}

$end = microtime(true);
echo 'Word comparisons: ' . $steps . ' within ' . ($end-$start) . ' (ms)';